package fair.controller;

import fair.entity.Result;
import fair.pojo.User;
import fair.service.IUserService;
import fair.utils.Md5Util;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

/**
 * @author: Jingtao_Wu
 * @DATE: 2021-02-26 10:32
 **/
@Api(tags = "用户管理")
@RestController
@RequestMapping("/user")
public class UserController {
    @Reference(version = "${dubbo.service.core.version}", group = "${dubbo.service.core.group}", timeout = 100000)
    private IUserService userService;

    /**
     * 用户根据用户名修改个人信息
     * @param user
     * @return
     */
    @ApiOperation("用户根据用户名修改个人信息")
    @RequestMapping(value = "updateInfo", method = RequestMethod.POST)
    public Result updateInfo(@RequestBody User user){
        user.setPassword(Md5Util.encode(user.getPassword()));
        try {
            userService.updateByUsername(user);
            return new Result(0, "");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(500, "内部异常");
        }
    }
}
